<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>easy-press</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>
    <style>
        body{
            background: #eee;
        }
        .container{
            max-width: 853px;
            margin: 0 auto;
            padding: 20px 15px;
        }
        .title{
            width: 100%;
            height: 38px;
            line-height: 38px;
            font-size: 18px;
            font-weight: 600;
            padding-left: 10px;
            box-sizing: border-box;
            margin-bottom: 15px;
        }
        .btn{
            margin-top: 15px;
            width: 80px;
            height: 30px;
            line-height: 30px;
            background: #467b96;
            border: none;
            color: #fff;
        }
        .toolbar {
        }
        .text {
            border: 1px solid #ccc;
            min-height: 550px;
            background: #fff;
        }
        .w-e-toolbar {
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            flex-wrap: wrap;
            padding: 0;
        }
    </style>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div class="container">
    <input type="text" class="title">
    <div id="editor">
        <div id="toolbar" class="toolbar">
        </div>
        <div id="text" class="text">
        </div>
    </div>
    <button class="btn" onclick="page.submit()" style="float: right">发布页面</button>
</div>
<script>
    const editor = new wangEditor('#toolbar','#text')
    // 或者 var editor = new E( document.getElementById('editor') )
    editor.create()
    const api={
        post(data){
            return axios.post('/admin/post', data)
        }
    }
    const page = {
        submit(){
            let title =  document.getElementsByClassName('title')[0].value;
            let content =  editor.txt.html();
            let post ={
                title,
                content
            }
            api.post(post).then(()=>{
                alert('保存成功')
            }).catch(()=>{
                alert('保存失敗')
            })
        }
    }
</script>
</body>
</html>